<template>

    <div>
    <el-button @click="Visible = true">上传科室文件</el-button>
    <div>
        <el-tree :data="data" style="float:left;margin-top: 0px;background-color:#f0f0f0;width: 100%" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
    </div>

    <el-dialog   v-model="Visible" width="420px" >
    <el-upload
            class="upload-demo"
            ref="upload"
            action="http://119.29.60.153:8001/doctorservice/department/addDepartment"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="file"
            :auto-upload="false">

        <div slot="tip"     class="el-upload__tip">只能上传Excel文件</div>
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>

    </el-upload>
        <center>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
        </center>
    </el-dialog>
    </div>
</template>

<script>
    import axios from "axios";
    import {ElMessage} from "element-plus";
    export default {
        name: "ManagerDepartment",
        data() {
            return{
                data:{
                    file: {name: '', url: ''},
                    id:'',
                    name:'',
                    children:[{
                        id:'',
                        name:''
                    }]
                },
                defaultProps: {
                    children: 'children',
                    label: 'name'
                },
                value: '',
                data:[],
                Visible:false,
            }

        },
        created(){
            this.create();
        },

        activated(){
            this.create();
        },

        methods:{
            create(){
                axios.get("http://119.29.60.153:8001/doctorservice/department/getAllDepartments").then(resp=> {
                    this.data=resp.data.data.list;
                })
            },
            handleNodeClick(data) {
                    if(data.children==null){
                        localStorage.setItem('departmentId',data.id);
                        localStorage.setItem('departmentname',data.name);
                        this.$router.push({name:'Scheduling',})
                    }
                },
            submitUpload() {
                this.$refs.upload.submit();
                this.Visible = false;

                alert("上传成功!");
                location.reload();

            },

        }

    }
</script>

<style>
</style>